package com.ygly.struts.href;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.ygly.struts.actions.ContextAction;
import com.ygly.struts.actions.SqlAction;
import com.ygly.struts.models.User;

public class Href6Action extends ActionSupport {

	/**
	 * @return
	 */
	public List<User> userlist0;
	public List<User> userlist1;
	public List<User> list0 = new ArrayList<User>();
	public List<User> list1 = new ArrayList<User>();
	public List<User> getUserlist0() {
		return userlist0;
	}
	public void setUserlist0(List<User> userlist0) {
		this.userlist0 = userlist0;
	}
	public List<User> getUserlist1() {
		return userlist1;
	}
	public void setUserlist1(List<User> userlist1) {
		this.userlist1 = userlist1;
	}
	public String execute()throws Exception {
		// TODO Auto-generated method stub
		ActionContext con = ActionContext.getContext();
		HttpServletRequest request = (HttpServletRequest )con.get(ServletActionContext.HTTP_REQUEST);
		int id;
		if(request.getParameter("id")!=null){
			id = Integer.parseInt(request.getParameter("id"));
		}else{
			id = (Integer) request.getAttribute("iddd");
		}
		String query0 = "select * from stu_pro where Pro_Id='"+id+"' and State='0'";
		String query1 = "select * from stu_pro where Pro_Id='"+id+"' and State='1'";
		SqlAction sql = new SqlAction();
		sql.OpenConn();
		ResultSet rs0,rs1;
		rs0 = sql.executeQuery(query0);
		rs1 = sql.executeQuery(query1);
		while(rs0.next()){
			User user = new User();
			user.setName(rs0.getString("Stu_Name"));
			user.setId(rs0.getInt("Stu_Id"));
			list0.add(user);
		}
		while(rs1.next()){
			User user = new User();
			user.setName(rs1.getString("Stu_Name"));
			user.setId(rs1.getInt("Stu_Id"));
			list1.add(user);
		}
		this.setUserlist0(list0);
		this.setUserlist1(list1);
		ContextAction context = new ContextAction();
		context.request("proid", id);
		return "SUCCESS";
	}
}